package com.file;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Calendar;

import com.entity.Person;
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;

public class ObjectSeria {

	public static void main(String[] args) throws FileNotFoundException,
			IOException, ClassNotFoundException {
		String pathname = "C:" + File.separator + "aaa.txt";
		// obj(pathname);

		// wr(pathname);

		// data();
		// data_in();


	}

	private static void data() throws FileNotFoundException, IOException {
		String p = "C:" + File.separator + "aaab.bin";
		DataOutputStream out = new DataOutputStream(new FileOutputStream(
				new File(p)));
		short str = 11;
		out.writeInt(0xA);
		out.writeInt(0xAA);
		out.writeLong(0xA0);

		System.out.println("ok" + 0xA);

		DataInputStream dd = new DataInputStream(new FileInputStream(
				new File(p)));
		byte b[] = new byte[dd.available()];
		System.out.println("size=" + b.length);
		int i = dd.readInt();
		long l = dd.readLong();
		System.out.println(i);
		System.out.println(l);

	}

	private static void data_in() throws FileNotFoundException, IOException {
		String p = "D:" + File.separator + "数据记录" + File.separator
				+ "65010000_0001_20160918_120417_30MHz_3000MHz_25kHz_H_M.bin";
		DataInputStream dd = new DataInputStream(new FileInputStream(
				new File(p)));
		byte b[] = new byte[1000];
		dd.read(b);
		System.out.println(new String(b));

	}

	private static void wr(String pathname) throws FileNotFoundException,
			IOException {

		FileInputStream in = new FileInputStream(new File(pathname));
		byte[] b = new byte[1000];
		in.read(b);
		System.out.println(new String(b));
		System.out.println(new File(pathname).length());
	}

	private static void obj(String path) throws IOException,
			FileNotFoundException, ClassNotFoundException {
		ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
				new File(path)));
		ArrayList<Person> list = new ArrayList();
		for (int i = 0; i < 10; i++) {
			Person p = new Person();
			p.setName("name=" + i);
			list.add(p);
		}
		Person p = new Person();
		p.setName("name=123");
		out.writeObject(list);

		ObjectInputStream in = new ObjectInputStream(new FileInputStream(
				new File(path)));
		ArrayList<Person> list2 = (ArrayList<Person>) in.readObject();
		for (Person persion : list2) {
			System.out.println(persion.getName());

		}
	}
}
